package net.anzhuo.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.dao.GsContactInfoMapper;
import net.anzhuo.entity.GsContactInfo;
import net.anzhuo.service.GsContactInfoService;
@Service
public class GsContactInfoServiceImpl implements GsContactInfoService {

	@Autowired
	private GsContactInfoMapper gsContactInfoMapper;
	
	@Override
	public GsContactInfo getById(Long id) {
		// TODO Auto-generated method stub
		
		return gsContactInfoMapper.getById(id);
	}

	@Override
	public List<GsContactInfo> getBycoMd5(String coMd5) {
		// TODO Auto-generated method stub
		return gsContactInfoMapper.getBycoMd5(coMd5);
	}

	@Override
	public PaginationVO<GsContactInfo> getListWithPage(GsContactInfo gsContactInfo) {
		PaginationVO<GsContactInfo> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsContactInfoMapper.getListWithPage(gsContactInfo));
		paginationVO.setTotalCount(gsContactInfoMapper.getCount(gsContactInfo));
		paginationVO.setTotalPage((gsContactInfoMapper.getCount(gsContactInfo) + gsContactInfo.getPageSize() -1)  / gsContactInfo.getPageSize());
		paginationVO.setPageNo(gsContactInfo.getPageNo());
		return paginationVO;
	}

	@Override
	public List<GsContactInfo> getList() {
		// TODO Auto-generated method stub
		return  gsContactInfoMapper.getList();
	}

	@Override
	public List<GsContactInfo> getList(GsContactInfo gsContactInfo) {
		// TODO Auto-generated method stub
		return gsContactInfoMapper.getListByQuery(gsContactInfo);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsContactInfo gsContactInfo) {
		// TODO Auto-generated method stub
		gsContactInfoMapper.update(gsContactInfo);

	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsContactInfo gsContactInfo) {
		// TODO Auto-generated method stub
		gsContactInfoMapper.save(gsContactInfo);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsContactInfo gsContactInfo = gsContactInfoMapper.getById(id);
		if (gsContactInfo == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsContactInfoMapper.update(gsContactInfo);

	}

}
